using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Configuration;using System.Collections;using System.Data.SqlClient;using System.Threading;namespace JL{ public partial class Login : Form { public Login() { InitializeComponent(); } private void Login_Load(object sender, EventArgs e) { DateTime dt = System.DateTime.Now; lab_systemtime.Text = string.Format("{0:yyyy-MM-dd HH:mm:ss}", dt); timer1.Start(); this.FormClosed = new FormClosedEventHandler(Login_FormClosed); } void Login_FormClosed(object sender, FormClosedEventArgs e) { Application.Exit(); } private void btn_exit_Click(object sender, EventArgs e) { if ((MessageBox.Show("你确定要退出计量系统吗?", "提示:", MessageBoxButtons.OKCancel)).ToString().Equals(MessageBoxButtons.OK.ToString())) { Application.Exit(); } } private void btn_login_Click(object sender, EventArgs e) { string suserid = this.txt_yhbm.Text.ToString().Trim(); string userkl = this.txt_kl.Text.ToString().Trim(); if (suserid == string.Empty) { MessageBox.Show("用户名不存在!", "登录失败!"); return; } string constring = ConfigurationManager.ConnectionStrings["connString"].ConnectionString.ToString(); SqlConnection conn = new SqlConnection(constring); if (conn.State == ConnectionState.Closed) { conn.Open(); } string sql = "select userid,username from T_USERINFO where userid='" suserid "' and userpass='" userkl "'"; SqlCommand cmd = new SqlCommand(sql, conn); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); sda.Fill(ds); string _userName = ""; if (ds.Tables[0].Rows.Count == 1) { _userName = ds.Tables[0].Rows[0][1].ToString(); userInfo.userId = suserid; userInfo.userName = _userName; userInfo.userPassWord = userkl; //ProBar pb = new ProBar(); //pb.Show(); formmain main = new formmain(); main.Show(); this.Hide(); conn.Close(); } else { this.txt_kl.Text = ""; MessageBox.Show("您输入的密码不正确,请重新输入","提示"); } } private void timer1_Tick(object sender, EventArgs e) { DateTime dt = System.DateTime.Now; lab_systemtime.Text = string.Format("{0:yyyy-MM-dd HH:mm:ss}", dt); } }}
评论